"""

@FileName：Daily Trading Information
@Author：马时易初
@Time：2024/4/5 14:34\n
@Copyright：©2019-2024 研发中心

"""
from selenium import webdriver
from selenium.webdriver.common.by import By
import pymysql
conn = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="root", database="stock_spider")
cursor = conn.cursor()


wd = webdriver.Chrome()
wd.get('https://quote.eastmoney.com/sh603818.html')
wd.implicitly_wait(3)

Trades=[]
Opening_Prices = wd.find_elements(By.XPATH, '//div[@class="brief_info_c"]/table/tbody/tr/td/span')
for Opening_Price in Opening_Prices:
    if Opening_Price.text:
        Trades.append(Opening_Price.text)

sql = "insert into daily_trading_information(Open, High, Upper_Limit, Turnover_Rate, Volume, Dynamic_PE_Ratio, Market_Capitalization, Ye_Close, Low, Lower_Limit, Volume_Ratio, Transaction_Amount, Price_to_Book_Ratio, Circilating_Msrket_Value) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s"
print(Trades)
cursor.executemany(sql, Trades)

try:
    conn.commit()
    print(0)
    cursor.close()
    conn.close()

except:
    print(1)

# Opening_Price = [Opening_Price.text for Opening_Price in Opening_Prices]
# print(Opening_Price)
# wd.quit()





